package com.espirit.builder.base;

import org.springframework.stereotype.Component;

import com.espirit.common.RelatedFile;
import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.GridSection;
import com.espirit.eap.pagelayout.ModelField;
import com.espirit.eap.pagelayout.SectionElement;

@Component
public class RelatedFileBuilder extends ModelBuilderSupport {
	private static final String FIELD_REMARK="remark";
	private static final String FIELD_FILE="file";
	
	@Override
	public boolean init() {
		return super.setClass(RelatedFile.class, "Related File", "相关文件") ;
	}
	@Override
	public void buildFields() {
		addModelField(FIELD_FILE, "File", "文件");
		addModelField(FIELD_REMARK, "Remark", "说明");
	}
	
	
	@Override
	protected void setDefaultLayoutButtons() {
		
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(FIELD_REMARK, FIELD_FILE));
	}
	
	
	@Override
	protected void preBuildMiscDatas() {
		if (model.getDefaultListLayout() == null) return ;
		GridSection grid = model.getDefaultListLayout().getMainGridSection();
		if (grid != null){
			grid.setReadOnly(false);
			grid.setTagName("datagrid");
			SectionElement remark = grid.getSectionElement(FIELD_REMARK);
			remark.setWidth(300);
			
			SectionElement file = grid.getSectionElement(FIELD_FILE);
			file.setWidth(220);
			
			updateObject(model);
		}
		super.preBuildMiscDatas();
	}
}
